<?php

namespace app\common\controller;


use app\api\controller\Error;
use app\BaseController;
use app\common\service\SignService;
use think\exception\ValidateException;
use app\api\model\Order;

class ApiController extends BaseController
{
    // 跳过验签的方法
    protected $noNeedSign = [
        'doPoints',
    ];

    public $app_type;


    protected function initialize()
    {
        $action = request()->action();
        if (!in_array($action, $this->noNeedSign)) {
            $this->verifySign();
        }
    }

    protected function verifySign()
    {
        $params = request()->param();

        if (!empty($params['sysNumber'])){
            $see_order =Order::where('sys_number', $params['sysNumber'])->find();
            
            if (!empty($see_order)){
                $this->app_type = get_app_type_str($see_order['app_type']);
            }
        }elseif(!empty($params['app_type'])){
            $this->app_type = $params['app_type'];
        }


        if (empty($this->app_type) || !in_array($this->app_type,['dada_pro','fengniao_pro','shansong_pro','dada_dev','fengniao_dev','shansong_dev'])){
            output_error('未获取到平台类型');
        }

        $signRider = new SignService();
        $res = $signRider->verifyRiderSign($params);
        $status = !empty($res['status']) ? $res['status'] : 0;
        if (empty($status)){
            $msg = !empty($res['msg']) ? $res['msg'] : '签名验证失败';
            output_error($msg);
        }
    }

}